import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib
from matplotlib import font_manager, rc
import plotly
import cufflinks as cf
import platform
import numpy as np
import time
path = "C:/Windows/Fonts/malgun.ttf"
if platform.system() == "Windows":
font_name = font_manager.FontProperties(fname=path).get_name()
rc('font', family=font_name)
elif platform.system()=="Darwin":
rc('font', family='AppleGothic')
else:
print("Unknown System")
matplotlib.rcParams['axes.unicode_minus'] = False
bike_sum = pd.read_csv('./data_set/공공자전거_이용건수_소계.csv')
bike_sum.head()
| 대여일자 | 여성 | 남성 | 미상 | 총 이용건수 | AGE_001 | AGE_002 | AGE_003 | AGE_004 | AGE_005 | AGE_006 | AGE_007 | AGE_008 | AGE_009 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Jan-20 | 113769 | 258052 | 422341 | 794162 | 28787 | 326277 | 187520 | 127519 | 79939 | 23260 | 5060 | 15800 | 0 |
| 1 | Feb-20 | 119053 | 249361 | 393860 | 762274 | 29083 | 317169 | 176534 | 121663 | 75398 | 21048 | 4586 | 16793 | 0 |
| 2 | Mar-20 | 264416 | 392151 | 876968 | 1533535 | 76255 | 704244 | 333664 | 215159 | 122946 | 32372 | 6520 | 42375 | 0 |
| 3 | Apr-20 | 356697 | 498752 | 1301941 | 2157390 | 119026 | 995677 | 485148 | 299685 | 161736 | 39643 | 7573 | 48902 | 0 |
| 4 | May-20 | 373831 | 531646 | 1574853 | 2480330 | 136688 | 1164916 | 559575 | 335044 | 179794 | 44223 | 8235 | 51855 | 0 |
bike_sum.columns
Index(['대여일자', '여성', '남성', '미상', '총 이용건수', 'AGE_001', 'AGE_002', 'AGE_003',
'AGE_004', 'AGE_005', 'AGE_006', 'AGE_007', 'AGE_008', 'AGE_009'],
dtype='object')
sns.barplot(x='대여일자', y='총 이용건수', data=bike_sum)
plt.xticks(rotation=45)
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17]),
[Text(0, 0, 'Jan-20'),
Text(1, 0, 'Feb-20'),
Text(2, 0, 'Mar-20'),
Text(3, 0, 'Apr-20'),
Text(4, 0, 'May-20'),
Text(5, 0, 'Jun-20'),
Text(6, 0, 'Jul-20'),
Text(7, 0, 'Aug-20'),
Text(8, 0, 'Sep-20'),
Text(9, 0, 'Oct-20'),
Text(10, 0, 'Nov-20'),
Text(11, 0, 'Dec-20'),
Text(12, 0, 'Jan-21'),
Text(13, 0, 'Feb-21'),
Text(14, 0, 'Mar-21'),
Text(15, 0, 'Apr-21'),
Text(16, 0, 'May-21'),
Text(17, 0, 'Jun-21')])
# 남성 이용객의 대여일자별 이용건수
sns.lineplot(x='대여일자', y='남성', data=bike_sum)
plt.xticks(rotation=45)
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, '')])
sns.barplot(x='대여일자', y='남성', data=bike_sum)
plt.xticks(rotation=45)
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17]),
[Text(0, 0, 'Jan-20'),
Text(1, 0, 'Feb-20'),
Text(2, 0, 'Mar-20'),
Text(3, 0, 'Apr-20'),
Text(4, 0, 'May-20'),
Text(5, 0, 'Jun-20'),
Text(6, 0, 'Jul-20'),
Text(7, 0, 'Aug-20'),
Text(8, 0, 'Sep-20'),
Text(9, 0, 'Oct-20'),
Text(10, 0, 'Nov-20'),
Text(11, 0, 'Dec-20'),
Text(12, 0, 'Jan-21'),
Text(13, 0, 'Feb-21'),
Text(14, 0, 'Mar-21'),
Text(15, 0, 'Apr-21'),
Text(16, 0, 'May-21'),
Text(17, 0, 'Jun-21')])
bike_2020 = pd.read_csv('./data_set/공공자전거 이용정보(2020년 전월).csv', encoding = 'cp949')
bike_2020.columns
Index(['대여일자', '대여소번호', '대여소명', '대여구분코드', '성별', '연령대코드', '이용건수', '운동량', '탄소량',
'이동거리', '이용시간', '여성', '남성', '미상', '총 이용건수', 'AGE_001', 'AGE_002',
'AGE_003', 'AGE_004', 'AGE_005', 'AGE_006', 'AGE_007', 'AGE_008',
'AGE_009'],
dtype='object')
bike_2020 = bike_2020.drop(['여성', '남성', '미상', '총 이용건수', 'AGE_001', 'AGE_002',
'AGE_003', 'AGE_004', 'AGE_005', 'AGE_006', 'AGE_007', 'AGE_008',
'AGE_009'],axis=1)
bike_2020.head(7)
| 대여일자 | 대여소번호 | 대여소명 | 대여구분코드 | 성별 | 연령대코드 | 이용건수 | 운동량 | 탄소량 | 이동거리 | 이용시간 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 20-Jan | 3 | 중랑센터 | 일일(회원) | M | AGE_003 | 3 | 61.82 | 0.52 | 2230.0 | 75 |
| 1 | 20-Jan | 3 | 중랑센터 | 일일(회원) | M | AGE_004 | 1 | 39.62 | 0.28 | 1220.0 | 15 |
| 2 | 20-Jan | 3 | 중랑센터 | 정기 | M | AGE_005 | 3 | 430.85 | 4.01 | 17270.0 | 53 |
| 3 | 20-Jan | 5 | 상암센터 정비실 | 일일(회원) | \N | AGE_005 | 2 | 1.79 | 0.02 | 90.0 | 33 |
| 4 | 20-Jan | 5 | 상암센터 정비실 | 정기 | F | AGE_003 | 1 | 4501.96 | 45.47 | 196010.0 | 64 |
| 5 | 20-Jan | 101 | 101. (구)합정동 주민센터 | 일일(비회원) | \N | AGE_008 | 2 | 341.31 | 3.07 | 13260.0 | 121 |
| 6 | 20-Jan | 101 | 101. (구)합정동 주민센터 | 일일(회원) | \N | AGE_002 | 15 | 1084.68 | 9.74 | 41990.0 | 382 |
# NULL 값이 있으면 'Unknwon'으로 채워준다.
bike_2020['성별'] = bike_2020['성별'].fillna('Unknown')
bike_2020['성별'].isnull().sum()
0
# 컬럼의 각 요소값 별로 데이터 수 확인
bike_2020['성별'].value_counts()
\N 472632 M 251108 F 225147 Name: 성별, dtype: int64
# M과 m을 m으로, F와 f를 f로, Nan와 \\N를 nan으로 통합
print('통일 전 <성별>컬럼에 있는 유니크 값 : ', bike_2020['성별'].unique())
bike_2020['성별'] = bike_2020['성별'].map({'m':'M','M':'M', 'f':'F','F':"F", '\\N':'Unknown'})
print('통일 후 <성별>컬럼에 있는 유니크 값 : ', bike_2020['성별'].unique())
통일 전 <성별>컬럼에 있는 유니크 값 : ['M' '\\N' 'F'] 통일 후 <성별>컬럼에 있는 유니크 값 : ['M' 'Unknown' 'F']
# 여자-0, 남자-1, 알수없음-2
# bike_2020['성별'] = bike_2020['성별'].map({'F':0,'0':0, 'M':1,'1':1, 'Unknwon' :2})
# bike_2020['성별'].unique()
# 확인
bike_2020[['대여일자','성별','연령대코드','이용건수','운동량','이동거리','이용시간']]
| 대여일자 | 성별 | 연령대코드 | 이용건수 | 운동량 | 이동거리 | 이용시간 | |
|---|---|---|---|---|---|---|---|
| 0 | 20-Jan | M | AGE_003 | 3 | 61.82 | 2230.0 | 75 |
| 1 | 20-Jan | M | AGE_004 | 1 | 39.62 | 1220.0 | 15 |
| 2 | 20-Jan | M | AGE_005 | 3 | 430.85 | 17270.0 | 53 |
| 3 | 20-Jan | Unknown | AGE_005 | 2 | 1.79 | 90.0 | 33 |
| 4 | 20-Jan | F | AGE_003 | 1 | 4501.96 | 196010.0 | 64 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 948882 | 20-Dec | F | AGE_006 | 1 | 0.00 | 0.0 | 0 |
| 948883 | 20-Dec | M | AGE_003 | 2 | 0.00 | 0.0 | 76 |
| 948884 | 20-Dec | M | AGE_004 | 1 | 0.00 | 0.0 | 15 |
| 948885 | 20-Dec | Unknown | AGE_008 | 7 | 0.00 | 0.0 | 18 |
| 948886 | 20-Dec | M | AGE_004 | 3 | 0.00 | 0.0 | 15 |
948887 rows × 7 columns
sns.countplot(x='대여일자', data=bike_2020).set_title('월별 공공 자전거 총 이용건수')
plt.xticks(rotation=45)
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [Text(0, 0, '20-Jan'), Text(1, 0, '20-Feb'), Text(2, 0, '20-Mar'), Text(3, 0, '20-Apr'), Text(4, 0, '20-May'), Text(5, 0, '20-Jun'), Text(6, 0, '20-Jul'), Text(7, 0, '20-Aug'), Text(8, 0, '20-Sep'), Text(9, 0, '20-Oct'), Text(10, 0, '20-Nov'), Text(11, 0, '20-Dec')])
sns.lineplot(x='대여일자', y ='이용건수', data=bike_2020).set(title='한 사람당 월별 평균 이용건수')
plt.xticks(rotation=45)
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, '')])
# 성별 오름차순
bike_2020=bike_2020.sort_values(by='성별', ascending=True)
sns.countplot(x='성별',data=bike_2020)
<AxesSubplot:xlabel='성별', ylabel='count'>
sns.barplot(x='성별', y='이용건수',data=bike_2020)
<AxesSubplot:xlabel='성별', ylabel='이용건수'>
sns.countplot(x='대여일자', hue='성별',data=bike_2020)
plt.xticks(rotation=45)
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [Text(0, 0, '20-Jun'), Text(1, 0, '20-Mar'), Text(2, 0, '20-May'), Text(3, 0, '20-Jul'), Text(4, 0, '20-Oct'), Text(5, 0, '20-Sep'), Text(6, 0, '20-Apr'), Text(7, 0, '20-Aug'), Text(8, 0, '20-Dec'), Text(9, 0, '20-Jan'), Text(10, 0, '20-Nov'), Text(11, 0, '20-Feb')])
sns.barplot(x='성별', y='이용건수',data=bike_2020)
<AxesSubplot:xlabel='성별', ylabel='이용건수'>
sns.barplot(x='성별', y='이용시간',data=bike_2020)
<AxesSubplot:xlabel='성별', ylabel='이용시간'>
bike_2020.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 948887 entries, 378739 to 663810 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 대여일자 948887 non-null object 1 대여소번호 948887 non-null int64 2 대여소명 948887 non-null object 3 대여구분코드 948887 non-null object 4 성별 948887 non-null object 5 연령대코드 948887 non-null object 6 이용건수 948887 non-null int64 7 운동량 948887 non-null float64 8 탄소량 948887 non-null float64 9 이동거리 948887 non-null float64 10 이용시간 948887 non-null int64 dtypes: float64(3), int64(3), object(5) memory usage: 119.1+ MB
bike_2020['운동량'].tail(20).unique()
array([ 0. , 180.15, 24.71, 374.34, 280.05, 1844.79, 236.25,
183.78])
bike_2020['운동량'].value_counts()
0.00 292258
43.24 147
46.33 138
36.04 130
21.62 126
...
7100.33 1
3719.26 1
5341.37 1
11046.11 1
2440.07 1
Name: 운동량, Length: 279971, dtype: int64
bike_2020['운동량'] = bike_2020['운동량'].str.replace(pat=r'\\N', repl=r'0', regex=True)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-90-adb5f17ea7e6> in <module> ----> 1 bike_2020['운동량'] = bike_2020['운동량'].str.replace(pat=r'\\N', repl=r'0', regex=True) ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py in __getattr__(self, name) 5459 or name in self._accessors 5460 ): -> 5461 return object.__getattribute__(self, name) 5462 else: 5463 if self._info_axis._can_hold_identifiers_and_holds_name(name): ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/accessor.py in __get__(self, obj, cls) 178 # we're accessing the attribute of the class, i.e., Dataset.geo 179 return self._accessor --> 180 accessor_obj = self._accessor(obj) 181 # Replace the property with the accessor object. Inspired by: 182 # https://www.pydanny.com/cached-property.html ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/strings/accessor.py in __init__(self, data) 152 from pandas.core.arrays.string_ import StringDtype 153 --> 154 self._inferred_dtype = self._validate(data) 155 self._is_categorical = is_categorical_dtype(data.dtype) 156 self._is_string = isinstance(data.dtype, StringDtype) ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/strings/accessor.py in _validate(data) 215 216 if inferred_dtype not in allowed_types: --> 217 raise AttributeError("Can only use .str accessor with string values!") 218 return inferred_dtype 219 AttributeError: Can only use .str accessor with string values!
# 운동량 컬럼에 \N이 있는 칸은 0으로 바꾼다.
# print('값 변환 전 :',bike_2020['운동량'].unique())
# bike_2020['운동량'] = bike_2020['운동량'].map({'\\N':0, '0':0})
# print('값 변환 후 :',bike_2020['운동량'].unique())
bike_2020[['대여일자','성별','연령대코드','이용건수','운동량','이동거리','이용시간']]
| 대여일자 | 성별 | 연령대코드 | 이용건수 | 운동량 | 이동거리 | 이용시간 | |
|---|---|---|---|---|---|---|---|
| 378739 | 20-Jun | F | AGE_001 | 2 | 0.00 | 0.00 | 21 |
| 171435 | 20-Mar | F | AGE_005 | 1 | 69.11 | 2770.00 | 34 |
| 171436 | 20-Mar | F | AGE_006 | 1 | 322.42 | 13800.00 | 80 |
| 308615 | 20-May | F | AGE_001 | 5 | 94.28 | 3840.00 | 133 |
| 486129 | 20-Jul | F | AGE_002 | 321 | 16902.71 | 736255.15 | 8541 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 585714 | 20-Aug | \N | AGE_007 | 30 | 0.00 | 0.00 | 858 |
| 585713 | 20-Aug | \N | AGE_006 | 8 | 0.00 | 0.00 | 260 |
| 585712 | 20-Aug | \N | AGE_005 | 45 | 0.00 | 0.00 | 1058 |
| 243339 | 20-Apr | \N | AGE_004 | 4 | 236.25 | 8210.00 | 128 |
| 663810 | 20-Sep | \N | AGE_002 | 8 | 183.78 | 8438.02 | 665 |
948887 rows × 7 columns
print('자료형 변환 전 :', bike_2020['운동량'].dtypes)
bike_2020['운동량'] = bike_2020['운동량'].astype('float64')
print('자료형 변환 후 :',bike_2020['운동량'].dtypes)
자료형 변환 전 : float64 자료형 변환 후 : float64
sns.barplot(x='성별', y='운동량',data=bike_2020)
<AxesSubplot:xlabel='성별', ylabel='운동량'>
bike_2020.loc[1,['이용시간']].values == 15
array([ True])
if bike_2020['이용시간'].values == 0:
bike_2020['운동강도'].values = 0
else :
bike_2020['운동강도'].values = bike_2020['운동량'].values/ bike_2020['이용시간'].values
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-95-a0f3bae1501f> in <module> ----> 1 if bike_2020['이용시간'].values == 0: 2 bike_2020['운동강도'].values = 0 3 else : 4 bike_2020['운동강도'].values = bike_2020['운동량'].values/ bike_2020['이용시간'].values ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
for i in range(948887):
if bike_2020.loc[i,['이용시간']].values == 0:
bike_2020.loc[i,['운동강도']].values = 0
else :
bike_2020.loc[i,['운동강도']].values = bike_2020.loc[i,['운동량']].values/ bike_2020.loc[i,['이용시간']].values
sns.barplot(x='성별', y=bike_2020['운동량'].values/ bike_2020['이용시간'].values ,data=bike_2020)
<ipython-input-326-3f99a598931f>:1: RuntimeWarning: divide by zero encountered in true_divide sns.barplot(x='성별', y=bike_2020['운동량'].values/ bike_2020['이용시간'].values ,data=bike_2020) <ipython-input-326-3f99a598931f>:1: RuntimeWarning: invalid value encountered in true_divide sns.barplot(x='성별', y=bike_2020['운동량'].values/ bike_2020['이용시간'].values ,data=bike_2020) /Users/works/opt/anaconda3/lib/python3.8/site-packages/numpy/lib/function_base.py:3961: RuntimeWarning: invalid value encountered in subtract diff_b_a = subtract(b, a)
<AxesSubplot:xlabel='성별'>
sns.barplot(x='성별', y='이동거리', data=bike_2020).set(title='성별에 따른 한 사람 평균 이동거리')
sns.barplot(x='성별', y='이동거리'/'이용시간', data=bike_2020).set(title='성별에 따른 한 사람 평균 주행속도')
plt.xticks(rotation=30)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-33-d6077f419a30> in <module> ----> 1 sns.barplot(x='성별', y='이동거리'/'이용시간', data=bike_2020).set(title='성별에 따른 한 사람 평균 주행속도') 2 plt.xticks(rotation=30) TypeError: unsupported operand type(s) for /: 'str' and 'str'
sns.countplot(x='연령대코드',data=bike_2020).set(title='나이대별 총 이용건수')
plt.xticks(rotation=30)
bike_2020=bike_2020.sort_values(by='연령대코드', ascending=True)
sns.countplot(x='연령대코드',data=bike_2020).set(title='나이대별 총 이용건수')
plt.xticks(rotation=30)
# 연령대 오름차순 정렬
bike_2020=bike_2020.sort_values(by='연령대코드', ascending=True)
sns.barplot(x='연령대코드',y='이용시간',data=bike_2020).set(title='나이대별 한 사람의 평균 이용시간')
plt.xticks(rotation=30)
(array([0, 1, 2, 3, 4, 5, 6, 7]), [Text(0, 0, 'AGE_001'), Text(1, 0, 'AGE_002'), Text(2, 0, 'AGE_003'), Text(3, 0, 'AGE_004'), Text(4, 0, 'AGE_005'), Text(5, 0, 'AGE_006'), Text(6, 0, 'AGE_007'), Text(7, 0, 'AGE_008')])
sns.countplot(x='연령대코드', hue = '성별',data=bike_2020).set(title='나이대별로 남녀 총 이용건수 차이')
plt.xticks(rotation=30)
(array([0, 1, 2, 3, 4, 5, 6, 7]), [Text(0, 0, 'AGE_001'), Text(1, 0, 'AGE_002'), Text(2, 0, 'AGE_003'), Text(3, 0, 'AGE_004'), Text(4, 0, 'AGE_005'), Text(5, 0, 'AGE_006'), Text(6, 0, 'AGE_007'), Text(7, 0, 'AGE_008')])
sns.barplot(x='연령대코드', y='이용건수',data=bike_2020).set(title='나이대별 한 사람의 한달 평균 이용횟수')
plt.xticks(rotation=30)
(array([0, 1, 2, 3, 4, 5, 6, 7]), [Text(0, 0, 'AGE_001'), Text(1, 0, 'AGE_002'), Text(2, 0, 'AGE_003'), Text(3, 0, 'AGE_004'), Text(4, 0, 'AGE_005'), Text(5, 0, 'AGE_006'), Text(6, 0, 'AGE_007'), Text(7, 0, 'AGE_008')])
bike_2020 = pd.read_csv('./data_set/공공자전거 이용정보(2020년 전월).csv', encoding = 'cp949')
sns.countplot(x='대여일자', data=bike_2020).set_title('월별 공공 자전거 총 이용건수')
plt.xticks(rotation=45)
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [Text(0, 0, '20-Jan'), Text(1, 0, '20-Feb'), Text(2, 0, '20-Mar'), Text(3, 0, '20-Apr'), Text(4, 0, '20-May'), Text(5, 0, '20-Jun'), Text(6, 0, '20-Jul'), Text(7, 0, '20-Aug'), Text(8, 0, '20-Sep'), Text(9, 0, '20-Oct'), Text(10, 0, '20-Nov'), Text(11, 0, '20-Dec')])
sns.lineplot(x='대여일자', y ='이용시간', data=bike_2020).set(title='한 사람당 월별 평균 이용시간')
plt.xticks(rotation=45)
bike_2020.iplot(kind='line', x='대여일자',y='이용시간', theme='space')
/Users/works/opt/anaconda3/lib/python3.8/site-packages/chart_studio/plotly/plotly.py:222: UserWarning: Woah there! Look at all those points! Due to browser limitations, the Plotly SVG drawing functions have a hard time graphing more than 500k data points for line charts, or 40k points for other types of charts. Here are some suggestions: (1) Use the `plotly.graph_objs.Scattergl` trace object to generate a WebGl graph. (2) Trying using the image API to return an image instead of a graph URL (3) Use matplotlib (4) See if you can create your visualization with fewer data points If the visualization you're using aggregates points (e.g., box plot, histogram, etc.) you can disregard this warning.
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) <ipython-input-37-bb9bebdae625> in <module> ----> 1 bike_2020.iplot(kind='line', x='대여일자',y='이용시간', theme='space') ~/opt/anaconda3/lib/python3.8/site-packages/cufflinks/plotlytools.py in _iplot(self, kind, data, layout, filename, sharing, title, xTitle, yTitle, zTitle, theme, colors, colorscale, fill, width, dash, mode, interpolation, symbol, size, barmode, sortbars, bargap, bargroupgap, bins, histnorm, histfunc, orientation, boxpoints, annotations, keys, bestfit, bestfit_colors, mean, mean_colors, categories, x, y, z, text, gridcolor, zerolinecolor, margin, labels, values, secondary_y, secondary_y_title, subplots, shape, error_x, error_y, error_type, locations, lon, lat, asFrame, asDates, asFigure, asImage, dimensions, asPlot, asUrl, online, **kwargs) 1214 return Figure(figure) 1215 else: -> 1216 return iplot(figure,validate=validate,sharing=sharing,filename=filename, 1217 online=online,asImage=asImage,asUrl=asUrl,asPlot=asPlot, 1218 dimensions=dimensions,display_image=kwargs.get('display_image',True)) ~/opt/anaconda3/lib/python3.8/site-packages/cufflinks/plotlytools.py in iplot(figure, validate, sharing, filename, online, asImage, asUrl, asPlot, dimensions, display_image, **kwargs) 1468 return offline.py_offline.iplot(figure, validate=validate, filename=filename, show_link=show_link, link_text=link_text, config=config) 1469 else: -> 1470 return py.iplot(figure,validate=validate,sharing=sharing, 1471 filename=filename) 1472 ~/opt/anaconda3/lib/python3.8/site-packages/chart_studio/plotly/plotly.py in iplot(figure_or_data, **plot_options) 133 if "auto_open" not in plot_options: 134 plot_options["auto_open"] = False --> 135 url = plot(figure_or_data, **plot_options) 136 137 if isinstance(figure_or_data, dict): ~/opt/anaconda3/lib/python3.8/site-packages/chart_studio/plotly/plotly.py in plot(figure_or_data, validate, **plot_options) 274 grid_filename = filename + "_grid" 275 --> 276 grid_ops.upload( 277 grid=grid, 278 filename=grid_filename, ~/opt/anaconda3/lib/python3.8/site-packages/chart_studio/plotly/plotly.py in upload(cls, grid, filename, world_readable, auto_open, meta) 1085 payload["parent_path"] = parent_path 1086 -> 1087 file_info = _create_or_overwrite_grid(payload) 1088 1089 cols = file_info["cols"] ~/opt/anaconda3/lib/python3.8/site-packages/chart_studio/plotly/plotly.py in _create_or_overwrite_grid(data, max_retries) 1526 if filename: 1527 try: -> 1528 lookup_res = v2.files.lookup(filename) 1529 if isinstance(lookup_res.content, bytes): 1530 content = lookup_res.content.decode("utf-8") ~/opt/anaconda3/lib/python3.8/site-packages/chart_studio/api/v2/files.py in lookup(path, parent, user, exists) 83 url = build_url(RESOURCE, route="lookup") 84 params = make_params(path=path, parent=parent, user=user, exists=exists) ---> 85 return request("get", url, params=params) ~/opt/anaconda3/lib/python3.8/site-packages/retrying.py in wrapped_f(*args, **kw) 47 @six.wraps(f) 48 def wrapped_f(*args, **kw): ---> 49 return Retrying(*dargs, **dkw).call(f, *args, **kw) 50 51 return wrapped_f ~/opt/anaconda3/lib/python3.8/site-packages/retrying.py in call(self, fn, *args, **kwargs) 204 205 if not self.should_reject(attempt): --> 206 return attempt.get(self._wrap_exception) 207 208 delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time ~/opt/anaconda3/lib/python3.8/site-packages/retrying.py in get(self, wrap_exception) 245 raise RetryError(self) 246 else: --> 247 six.reraise(self.value[0], self.value[1], self.value[2]) 248 else: 249 return self.value ~/opt/anaconda3/lib/python3.8/site-packages/six.py in reraise(tp, value, tb) 701 if value.__traceback__ is not tb: 702 raise value.with_traceback(tb) --> 703 raise value 704 finally: 705 value = None ~/opt/anaconda3/lib/python3.8/site-packages/retrying.py in call(self, fn, *args, **kwargs) 198 while True: 199 try: --> 200 attempt = Attempt(fn(*args, **kwargs), attempt_number, False) 201 except: 202 tb = sys.exc_info() ~/opt/anaconda3/lib/python3.8/site-packages/chart_studio/api/v2/utils.py in request(method, url, **kwargs) 170 171 try: --> 172 response = requests.request(method, url, **kwargs) 173 except RequestException as e: 174 # The message can be an exception. E.g., MaxRetryError. ~/opt/anaconda3/lib/python3.8/site-packages/requests/api.py in request(method, url, **kwargs) 59 # cases, and look like a memory leak in others. 60 with sessions.Session() as session: ---> 61 return session.request(method=method, url=url, **kwargs) 62 63 ~/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 540 } 541 send_kwargs.update(settings) --> 542 resp = self.send(prep, **send_kwargs) 543 544 return resp ~/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py in send(self, request, **kwargs) 695 696 if not stream: --> 697 r.content 698 699 return r ~/opt/anaconda3/lib/python3.8/site-packages/requests/models.py in content(self) 829 self._content = None 830 else: --> 831 self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' 832 833 self._content_consumed = True ~/opt/anaconda3/lib/python3.8/site-packages/requests/models.py in generate() 751 if hasattr(self.raw, 'stream'): 752 try: --> 753 for chunk in self.raw.stream(chunk_size, decode_content=True): 754 yield chunk 755 except ProtocolError as e: ~/opt/anaconda3/lib/python3.8/site-packages/urllib3/response.py in stream(self, amt, decode_content) 574 else: 575 while not is_fp_closed(self._fp): --> 576 data = self.read(amt=amt, decode_content=decode_content) 577 578 if data: ~/opt/anaconda3/lib/python3.8/site-packages/urllib3/response.py in read(self, amt, decode_content, cache_content) 517 else: 518 cache_content = False --> 519 data = self._fp.read(amt) if not fp_closed else b"" 520 if ( 521 amt != 0 and not data ~/opt/anaconda3/lib/python3.8/http/client.py in read(self, amt) 456 # Amount is given, implement using readinto 457 b = bytearray(amt) --> 458 n = self.readinto(b) 459 return memoryview(b)[:n].tobytes() 460 else: ~/opt/anaconda3/lib/python3.8/http/client.py in readinto(self, b) 500 # connection, and the user is reading more bytes than will be provided 501 # (for example, reading in 1k chunks) --> 502 n = self.fp.readinto(b) 503 if not n and b: 504 # Ideally, we would raise IncompleteRead if the content-length ~/opt/anaconda3/lib/python3.8/socket.py in readinto(self, b) 667 while True: 668 try: --> 669 return self._sock.recv_into(b) 670 except timeout: 671 self._timeout_occurred = True ~/opt/anaconda3/lib/python3.8/ssl.py in recv_into(self, buffer, nbytes, flags) 1239 "non-zero flags not allowed in calls to recv_into() on %s" % 1240 self.__class__) -> 1241 return self.read(nbytes, buffer) 1242 else: 1243 return super().recv_into(buffer, nbytes, flags) ~/opt/anaconda3/lib/python3.8/ssl.py in read(self, len, buffer) 1097 try: 1098 if buffer is not None: -> 1099 return self._sslobj.read(len, buffer) 1100 else: 1101 return self._sslobj.read(len) KeyboardInterrupt:
sns.lineplot(x='대여일자', y ='이동거리', data=bike_2020).set(title='한 사람당 월별 평균 이동거리')
plt.xticks(rotation=45)
sns.set_style("dark")
kkk
[Text(0.5, 1.0, '한 사람당 월별 평균 이동거리')]
/Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 45824 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 50668 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 51068 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 51088 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 54620 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 49324 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 46988 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 45817 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 50900 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 48324 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 54217 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 44512 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 51060 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 46041 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 44144 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:238: RuntimeWarning: Glyph 47532 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 45824 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 50668 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 51068 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 51088 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 51060 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 46041 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 44144 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 47532 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 54620 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 49324 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 46988 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 45817 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 50900 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 48324 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 54217 missing from current font. /Users/works/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:201: RuntimeWarning: Glyph 44512 missing from current font.
bike_2020.iplot(kind='line', x='대여일자',y='이동거리', theme='space')
pip install chart_studio
Collecting chart_studio
Downloading chart_studio-1.1.0-py3-none-any.whl (64 kB)
|████████████████████████████████| 64 kB 4.2 MB/s eta 0:00:011
Collecting retrying>=1.3.3
Downloading retrying-1.3.3.tar.gz (10 kB)
Requirement already satisfied: requests in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from chart_studio) (2.25.1)
Requirement already satisfied: six in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from chart_studio) (1.15.0)
Requirement already satisfied: plotly in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from chart_studio) (5.3.1)
Requirement already satisfied: tenacity>=6.2.0 in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from plotly->chart_studio) (8.0.1)
Requirement already satisfied: certifi>=2017.4.17 in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from requests->chart_studio) (2020.12.5)
Requirement already satisfied: idna<3,>=2.5 in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from requests->chart_studio) (2.10)
Requirement already satisfied: chardet<5,>=3.0.2 in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from requests->chart_studio) (4.0.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/works/opt/anaconda3/lib/python3.8/site-packages (from requests->chart_studio) (1.26.4)
Building wheels for collected packages: retrying
Building wheel for retrying (setup.py) ... done
Created wheel for retrying: filename=retrying-1.3.3-py3-none-any.whl size=11429 sha256=7a29d6e0ccbb0a605cebf5e2a92a3803a5b4b1a61e63d61457357bc33be3baa6
Stored in directory: /Users/works/Library/Caches/pip/wheels/c4/a7/48/0a434133f6d56e878ca511c0e6c38326907c0792f67b476e56
Successfully built retrying
Installing collected packages: retrying, chart-studio
Successfully installed chart-studio-1.1.0 retrying-1.3.3
Note: you may need to restart the kernel to use updated packages.
plt.plot(bike_2020['대여일자'], bike_2020['이동거리']) # line 그래프를 그립니다
plt.show()
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-28-7c5ac3182801> in <module> ----> 1 plt.plot(bike_2020.loc['대여일자'], bike_2020.loc['이동거리']) # line 그래프를 그립니다 2 plt.show() ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexing.py in __getitem__(self, key) 893 894 maybe_callable = com.apply_if_callable(key, self.obj) --> 895 return self._getitem_axis(maybe_callable, axis=axis) 896 897 def _is_scalar_access(self, key: Tuple): ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis) 1122 # fall thru to straight lookup 1123 self._validate_key(key, axis) -> 1124 return self._get_label(key, axis=axis) 1125 1126 def _get_slice_axis(self, slice_obj: slice, axis: int): ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexing.py in _get_label(self, label, axis) 1071 def _get_label(self, label, axis: int): 1072 # GH#5667 this will fail if the label is not present in the axis. -> 1073 return self.obj.xs(label, axis=axis) 1074 1075 def _handle_lowerdim_multi_index_axis0(self, tup: Tuple): ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level) 3737 raise TypeError(f"Expected label or tuple of labels, got {key}") from e 3738 else: -> 3739 loc = index.get_loc(key) 3740 3741 if isinstance(loc, np.ndarray): ~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance) 352 except ValueError as err: 353 raise KeyError(key) from err --> 354 raise KeyError(key) 355 return super().get_loc(key, method=method, tolerance=tolerance) 356 KeyError: '대여일자'
# 오류가 나는 상황
bike_2020.iplot(kind='line',x='대여일자',y='이용시간',theme='space', title='월별 한 사람 평균 이용시간')